<template>
  <div class="right">
    <dv-border-box-12 class="box-pit">
      <div class="date-content">
        <span>{{dateFormat(newDate)}}</span>
      </div>
      <div class="date-content">
        喷枪火焰：
        <span style="color: red">无</span>
      </div>
    </dv-border-box-12>
  </div>
</template>

<script>
export default {
  name: 'right',
  data () {
    return {
      // 当前时间
      newDate: new Date()
    }
  },
  mounted () {
    const that = this
    this.timer = setInterval(function () {
      that.newDate = new Date().toLocaleString()
    })
  },
  beforeUnmount: function () {
    if (this.timer) {
      clearInterval(this.timer)
    }
  },
  methods: {
    // 时间格式化
    dateFormat () {
      const date = new Date()
      const year = date.getFullYear()
      const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
      const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      const week = date.getDay() // 星期
      const weekArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
      return year + '年' + month + '月' + day + '日 ' + hours + ':' + minutes + ':' + seconds + ' ' + weekArr[week]
    }
  }

}
</script>

<style lang="scss">
.right{
  display: flex;
  height: 70%;
  width: 30%;
  margin-left: 100px;
}
.box-pit{
  display: flex;
  width: 50%;
  hight: 20%
}
.content-pit{
  font-size: 30px;
  margin-top: 180px;
}
.date-content{
  margin-left: 70px;
  margin-top: 70px;
  font-size: 50px;
}
</style>
